﻿using RRQMSkin;
using System;
using System.Media;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Animation;
using ViewModel.ViewModels;

namespace MainClient
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : RRQMWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            this.ViewModel = new MainViewModel(this);
            this.DataContext = ViewModel;

            Instance = this;
        }

        public MainViewModel ViewModel { get; private set; }

        public static MainWindow Instance { get; set; }

        public void PlaySound()
        {
            SoundPlayer player = new SoundPlayer("");

            player.Play();
        }

        private void WindowTitle_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DoubleAnimation doubleAnimation = new DoubleAnimation();
            doubleAnimation.From = 0;
            doubleAnimation.To = 1;
            doubleAnimation.Completed += DoubleAnimation_Completed;
            doubleAnimation.Duration = TimeSpan.FromSeconds(1.5);
            this.BeginAnimation(OpacityProperty, doubleAnimation);
        }

        private void DoubleAnimation_Completed(object sender, EventArgs e)
        {
            ThreadPool.QueueUserWorkItem((object o) => { this.ViewModel.GetMyInfo(); });
        }
    }
}